উদাহরণসহ একটি Customer Support Chatbot তৈরি করা

Latest Technologies - পাওয়ার প্লাটফর্ম (Power Platform) - Power Virtual Agents এর মাধ্যমে চ্যাটবট তৈরি
128

একটি কাস্টমার সাপোর্ট চ্যাটবট তৈরি করা একটি চিত্তাকর্ষক প্রকল্প যা ব্যবহারকারীদের প্রশ্নের উত্তর দিতে এবং তাদের সহায়তা করতে সক্ষম হয়। এখানে আমি Python ব্যবহার করে একটি সহজ কাস্টমার সাপোর্ট চ্যাটবট তৈরি করার প্রক্রিয়া দেখাব। এই চ্যাটবটটি Flask ফ্রেমওয়ার্ক এবং ChatterBot লাইব্রেরি ব্যবহার করে তৈরি করা হবে।

১. পরিবেশ সেটআপ

প্রথমে আপনার কম্পিউটারে Python এবং কিছু লাইব্রেরি ইনস্টল করতে হবে। নিচের কমান্ডগুলি চালান:

pip install Flask
pip install chatterbot
pip install chatterbot_corpus

২. Flask অ্যাপ তৈরি করা

২.১. প্রকল্পের কাঠামো

প্রকল্পের কাঠামো নিচের মতো হবে:

/customer_support_chatbot
    ├── app.py
    └── templates/
        └── index.html

২.২. ChatterBot সেটআপ

app.py ফাইল তৈরি করুন এবং নিচের কোড লিখুন:

# app.py

from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

app = Flask(__name__)

# ChatterBot তৈরি করা
chatbot = ChatBot('Customer Support Bot')

# ট্রেনার সেটআপ করা
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/get_response', methods=['POST'])
def get_response():
    user_message = request.form['message']
    bot_response = chatbot.get_response(user_message)
    return str(bot_response)

if __name__ == '__main__':
    app.run(debug=True)

২.৩. HTML টেমপ্লেট তৈরি করা

templates/index.html ফাইল তৈরি করুন এবং নিচের কোড লিখুন:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Customer Support Chatbot</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        #chatbox {
            width: 400px;
            height: 400px;
            border: 1px solid #ccc;
            padding: 10px;
            overflow-y: auto;
        }
        .user-message {
            color: blue;
        }
        .bot-response {
            color: green;
        }
    </style>
</head>
<body>
    <h1>Customer Support Chatbot</h1>
    <div id="chatbox"></div>
    <input type="text" id="user-input" placeholder="Type your message...">
    <button id="send-button">Send</button>

    <script>
        const sendButton = document.getElementById('send-button');
        const chatbox = document.getElementById('chatbox');

        sendButton.onclick = async () => {
            const userMessage = document.getElementById('user-input').value;
            chatbox.innerHTML += `<div class="user-message">User: ${userMessage}</div>`;
            document.getElementById('user-input').value = '';

            const response = await fetch('/get_response', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: `message=${userMessage}`
            });

            const botResponse = await response.text();
            chatbox.innerHTML += `<div class="bot-response">Bot: ${botResponse}</div>`;
            chatbox.scrollTop = chatbox.scrollHeight;  // Scroll to bottom
        };
    </script>
</body>
</html>

৩. অ্যাপ চালানো

অ্যাপ চালাতে নিচের কমান্ডটি চালান:

python app.py

৪. চ্যাটবট পরীক্ষা করা

আপনার ব্রাউজারে http://127.0.0.1:5000 এ যান। এখানে আপনি চ্যাটবটের সাথে কথোপকথন করতে পারবেন।

উপসংহার

এই উদাহরণটি দেখায় কিভাবে Python এবং Flask ব্যবহার করে একটি সহজ কাস্টমার সাপোর্ট চ্যাটবট তৈরি করা যায়। ChatterBot লাইব্রেরি ব্যবহার করে, আপনি বিভিন্ন প্রশ্নের উত্তর দিতে সক্ষম একটি চ্যাটবট তৈরি করতে পারেন। 

Promotion
NEW SATT AI এখন আপনাকে সাহায্য করতে পারে।

Are you sure to start over?

Loading...